<?php

/**
 * This is the model class for table "tg_Article".
 *
 * The followings are the available columns in table 'tg_Article':
 * @property integer $ID
 * @property integer $UID
 * @property string $Title
 * @property string $Content
 * @property string $UpdateTime
 * @property string $KeyWord
 * @property integer $Status
 * @property integer $ContentPoster
 * @property integer $RightPoster
 * @property integer $LeftPoster
 * @property string $Path
 */
class Article extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Article the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tg_Article';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('UID, Title, Content, UpdateTime, KeyWord, Status, ContentPoster, RightPoster, LeftPoster', 'required'),
			array('UID, Status, ContentPoster, RightPoster, LeftPoster', 'numerical', 'integerOnly'=>true),
			array('Title, KeyWord', 'length', 'max'=>64),
			array('Path', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID, UID, Title, Content, UpdateTime, KeyWord, Status, ContentPoster, RightPoster, LeftPoster, Path', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}
    public function defaultScope()
    {
        return array(
            'condition'=>'UID='.Yii::app()->user->id,
            'order'=>"UpdateTime DESC",
        );
    }

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'UID' => 'Uid',
			'Title' => '标题',
			'KeyWord' => '关键词',
			'Content' => '内容',
			'UpdateTime' => '更新时间',
			'Status' => '状态',
			'ContentPoster' => 'Content Poster',
			'RightPoster' => 'Right Poster',
			'LeftPoster' => 'Left Poster',
			'Path' => 'Path',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID',$this->ID);
		$criteria->compare('UID',$this->UID);
		$criteria->compare('Title',$this->Title,true);
		$criteria->compare('Content',$this->Content,true);
		$criteria->compare('UpdateTime',$this->UpdateTime,true);
		$criteria->compare('KeyWord',$this->KeyWord,true);
		$criteria->compare('Status',$this->Status);
		$criteria->compare('ContentPoster',$this->ContentPoster);
		$criteria->compare('RightPoster',$this->RightPoster);
		$criteria->compare('LeftPoster',$this->LeftPoster);
		$criteria->compare('Path',$this->Path,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}